{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import joblib \n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import gc\n",
    "import lightgbm as lgb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fold 0\n",
      "Training until validation scores don't improve for 10 rounds.\n",
      "[10]\ttraining's auc: 1\n",
      "Early stopping, best iteration is:\n",
      "[1]\ttraining's auc: 1\n"
     ]
    }
   ],
   "source": [
    "# train\n",
    "for i in range(1):\n",
    "    print('fold',i)\n",
    "    x_train = joblib.load('./train_data/x_df_fold{}.lz4'.format(i))\n",
    "    y_train = joblib.load('./train_data/y_fold0.lz4'.format(i))\n",
    "\n",
    "    parameters = {\n",
    "        'boost':'gbdt',\n",
    "        'num_leaves':120, \n",
    "        'scale_pos_weight':float(len(y_train)-np.sum(y_train))/float(np.sum(y_train)),\n",
    "        'max_depth':-1,\n",
    "        'learning_rate':.05,\n",
    "        'max_bin':200,\n",
    "        'min_data_in_leaf' : 100,\n",
    "        'objective':'binary',\n",
    "        'metric':'auc',\n",
    "        'num_threads':18\n",
    "    }\n",
    "\n",
    "\n",
    "    lgb_train = lgb.Dataset(x_train, y_train)\n",
    "\n",
    "    lgb_model = lgb.train(parameters,lgb_train,num_boost_round=250,\n",
    "                          early_stopping_rounds=10,\n",
    "                          valid_sets =lgb_train,\n",
    "                          verbose_eval=10)\n",
    "    joblib.dump(lgb_model,'./models/lgb{}'.format(i))\n",
    "    del x_train,y_train,lgb_model\n",
    "    gc.collect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
